<template>
	<a-card :bordered="false">
		<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="5">
					<a-form-item label="意图" name="intent">
						<a-select
							v-model:value="searchFormState.intent"
							placeholder="请选择意图"
							:options="callIntentOptions"
							allowClear
						/>
					</a-form-item>
				</a-col>
				<a-col :span="5">
					<a-form-item label="内容" name="subject">
						<a-input v-model:value="searchFormState.subject" placeholder="请输入内容" enter-button allowClear />
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
					<a-button style="margin: 0 8px" @click="reset">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
<!--	<QRGenerator-->
<!--		text="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wwe4c18b63c565e438&redirect_uri=123.118.99.242%3A9003%2Fapi%2Fauth%2Fb%2FdoLogin&response_type=code&scope=snsapi_base&agentid=1000013#wechat_redirect"-->
<!--	/>-->
	<a-card :bordered="false" class="mt-2">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
			:scroll="{ x: 'max-content' }"
		>
			<template #operator>
				<a-space>
					<a-button type="primary" @click="formRef.onOpen()">
						<template #icon>
							<plus-outlined />
						</template>
						新增
					</a-button>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="formRef.onOpen(record)">编辑</a>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="tableRef.refresh(true)" />
</template>

<script setup name="callScripts">
	import Form from '@/views/tjzy/call/scripts/form.vue'
	import QRGenerator from '@/components/QRGenerator/index.vue'
	import callAiApi from '@/api/tjzy/call/ai/callAiApi'
	import tool from '@/utils/tool'

	const searchFormState = ref({
		current: 1,
		size: 10
	})
	const tableRef = ref()
	const formRef = ref()
	const searchFormRef = ref()
	const callIntentOptions = tool.dictList('CallIntent')
	const columns = [
		{
			title: '意图',
			dataIndex: 'intentName'
		},
		{
			title: '话术',
			dataIndex: 'subject'
		},
		{
			title: '创建人',
			dataIndex: 'createUserName'
		},
		{
			title: '创建时间',
			dataIndex: 'createTime'
		},
		{
			title: '修改人',
			dataIndex: 'updateUserName'
		},
		{
			title: '修改时间',
			dataIndex: 'updateTime'
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center'
		}
	]
	const loadData = (parameter) => {
		searchFormState.value.current = parameter.current
		searchFormState.value.size = parameter.size
		return callAiApi.pageList(searchFormState.value).then((res) => {
			return res
		})
	}
	// 查询
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
</script>
